SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


/** Create Tables **/

/* Create stored procedures */
CREATE PROCEDURE dbo.[DnnProduct_CDS_TemplateUpdateStamp]
	@DistributorID varchar(50),
	@TemplateID int
AS
BEGIN
	IF NOT EXISTS(SELECT * FROM [DnnProduct_CDS_StampSets] WHERE TemplateID = @TemplateID AND (DefaultStampConfigID IS NOT NULL OR DefaultDRMStampConfigID IS NOT NULL))
	BEGIN
		IF NOT EXISTS(SELECT * FROM [DnnProduct_CDS_StampSets] WHERE TemplateID = @TemplateID AND (DefaultStampConfigID IS NULL AND DefaultDRMStampConfigID IS NULL))
		BEGIN
			INSERT INTO [DnnProduct_CDS_StampSets] (TemplateID, DefaultStampConfigID, DefaultDRMStampConfigID) VALUES (@TemplateID, NULL, NULL)
		END
	END
	ELSE
	BEGIN
		DELETE FROM [DnnProduct_CDS_StampSets] WHERE TemplateID = @TemplateID AND (DefaultStampConfigID IS NULL AND DefaultDRMStampConfigID IS NULL)
	END
END
GO
